package project.dbaccesslayer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.TreeMap;

import project.model.adt.User;

public class Table_SO_Users {
	
	public static void saveUser(Connection conn, User usr) throws SQLException {
		PreparedStatement s = conn.prepareStatement("INSERT INTO SO_Users"
				+ "(User_id,name,f_reputation,f_monthsNum) VALUES(?,?,?,?)");
		s.setLong(1, usr.id);
		s.setString(2, usr.name);
		s.setLong(3, usr.reputation);
		s.setLong(4, usr.numMonths);

		s.execute();
	}
	
	public static Map<Long, String> getUsersToParse(Connection conn)
			throws SQLException {
		PreparedStatement s = conn.prepareStatement("CALL GetUsersToParse(); ");
		ResultSet r = s.executeQuery();
		Map<Long, String> map = new TreeMap<Long, String>();
		while (r.next()) {
			map.put(r.getLong("User_id"), r.getString("html"));
		}
		return map;
	}
	
}
